/**
 * @since 2019-12-03
 */
import intl from 'utils/intl';
import { CPAAS_IAM, VERSION_IS_OP } from 'utils/config';
import { getCurrentOrganizationId } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
var checkStatusFormConfigDS = {
  autoCreate: true,
  fields: [{
    name: 'checkState',
    type: 'string',
    lookupCode: 'CIAM.PERMISSION_CHECK.STATE',
    defaultValue: 'PERMISSION_MISMATCH'
  }]
};
var searchFormConfigDS = {
  fields: [{
    name: 'permissionType',
    type: 'string',
    lookupCode: 'CIAM.PERMISSION_CHECK.PERMISSION_TYPE',
    label: intl.get('ciam.missPermission.model.missPermission.permissionType').d('权限类型')
  }, {
    name: 'menuName',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.menuName').d('菜单名称')
  }, {
    name: 'fdLevel',
    type: 'string',
    lookupCode: 'CIAM.PERMISSION_LEVEL',
    label: intl.get('ciam.missPermission.model.missPermission.levelMeaning').d('权限层级')
  }, {
    name: 'permissionCode',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.permissionCode').d('权限编码')
  }, {
    name: 'serviceNameLov',
    type: 'object',
    lovCode: 'CADM.SERVICE_CODE',
    label: intl.get('ciam.missPermission.model.missPermission.serviceName').d('服务名称'),
    noCache: true,
    ignore: 'always'
  }, {
    name: 'serviceName',
    type: 'string',
    bind: 'serviceNameLov.serviceCode'
  }, {
    name: 'handleStatus',
    type: 'string',
    lookupCode: 'CIAM.PERMISSION_CHECK.HANDLE_STATUS',
    label: intl.get('ciam.missPermission.model.missPermission.handleStatus').d('处理状态')
  }, {
    name: 'apiPath',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.apiPath').d('API路径')
  }, {
    name: 'apiMethod',
    type: 'string',
    lovPara: {
      tag: 'show'
    },
    lookupCode: 'CIAM.REQUEST_METHOD',
    label: intl.get('ciam.missPermission.model.missPermission.apiMethod').d('请求方式')
  }]
};

function tableConfigDS(checkStatusRecord, searchRecord) {
  return {
    autoQuery: true,
    dataKey: 'content',
    selection: 'multiple',
    fields: [{
      name: 'permissionCode',
      type: 'string',
      label: intl.get('ciam.missPermission.model.missPermission.permissionCode').d('权限编码')
    }, {
      name: 'menuName',
      type: 'string',
      label: intl.get('ciam.missPermission.model.missPermission.menuName').d('菜单名称')
    }, {
      name: 'apiPath',
      type: 'string',
      label: intl.get('ciam.missPermission.model.missPermission.apiPath').d('API路径')
    }, {
      name: 'checkState',
      type: 'string',
      label: intl.get('ciam.missPermission.model.missPermission.checkState').d('检查状态')
    }, {
      name: 'handleStatusMeaning',
      type: 'string',
      label: intl.get('ciam.missPermission.model.missPermission.handleStatusMeaning').d('处理状态')
    }, {
      name: 'checkStateMeaning',
      type: 'string',
      label: intl.get('ciam.missPermission.model.missPermission.checkStateMeaning').d('检查状态描述')
    }, {
      name: 'serviceName',
      type: 'string',
      label: intl.get('ciam.missPermission.model.missPermission.serviceName').d('服务名称')
    }, {
      name: 'apiMethodMeaning',
      type: 'string',
      label: intl.get('ciam.missPermission.model.missPermission.apiMethodMeaning').d('请求方式')
    }, {
      name: 'permissionType',
      type: 'string',
      label: intl.get('ciam.missPermission.model.missPermission.permissionType').d('权限类型')
    }, {
      name: 'creationDate',
      type: 'string',
      label: intl.get('ciam.missPermission.model.missPermission.creationDate').d('日期')
    }, {
      name: 'levelMeaning',
      type: 'string',
      label: intl.get('ciam.missPermission.model.missPermission.levelMeaning').d('权限层级')
    }],
    transport: {
      read: function read(config) {
        var _ref = checkStatusRecord.toJSONData()[0] || {},
            _ref$checkState = _ref.checkState,
            checkState = _ref$checkState === void 0 ? null : _ref$checkState;

        var _ref2 = searchRecord.toJSONData()[0] || {},
            _ref2$permissionCode = _ref2.permissionCode,
            permissionCode = _ref2$permissionCode === void 0 ? null : _ref2$permissionCode,
            _ref2$serviceName = _ref2.serviceName,
            serviceName = _ref2$serviceName === void 0 ? null : _ref2$serviceName,
            _ref2$handleStatus = _ref2.handleStatus,
            handleStatus = _ref2$handleStatus === void 0 ? null : _ref2$handleStatus,
            _ref2$apiPath = _ref2.apiPath,
            apiPath = _ref2$apiPath === void 0 ? null : _ref2$apiPath,
            _ref2$apiMethod = _ref2.apiMethod,
            apiMethod = _ref2$apiMethod === void 0 ? null : _ref2$apiMethod,
            _ref2$permissionType = _ref2.permissionType,
            permissionType = _ref2$permissionType === void 0 ? null : _ref2$permissionType,
            _ref2$fdLevel = _ref2.fdLevel,
            fdLevel = _ref2$fdLevel === void 0 ? null : _ref2$fdLevel,
            _ref2$menuName = _ref2.menuName,
            menuName = _ref2$menuName === void 0 ? null : _ref2$menuName;

        var params = config.params;
        var data = config.data;
        data = {
          checkState: checkState,
          permissionCode: permissionCode,
          serviceName: serviceName,
          handleStatus: handleStatus,
          apiPath: apiPath,
          apiMethod: apiMethod,
          permissionType: permissionType,
          fdLevel: fdLevel,
          menuName: menuName
        };
        var url = VERSION_IS_OP ? "".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/permission-check") : "".concat(CPAAS_IAM, "/v1/permission-check");
        return {
          data: data,
          params: params,
          url: url,
          method: 'GET'
        };
      }
    }
  };
}

var permissionSetDS = {
  dataKey: 'content',
  cacheSelection: true,
  queryFields: [{
    name: 'code',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.code').d('权限集编码')
  }, {
    name: 'parentName',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.parentName').d('父级菜单')
  }],
  fields: [{
    name: 'code',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.code').d('权限集编码')
  }, {
    name: 'name',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.name').d('权限集名称')
  }, {
    name: 'levelMeaning',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.levelMeaning').d('权限层级')
  }, {
    name: 'parentName',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.parentName').d('父级菜单')
  }],
  transport: {
    read: function read(config) {
      var params = config.params,
          data = config.data;
      var url = VERSION_IS_OP ? "".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/permission-check/permission-set") : "".concat(CPAAS_IAM, "/v1/permission-check/permission-set");
      return {
        data: data,
        params: params,
        url: url,
        method: 'GET'
      };
    }
  }
};
var clearPermissionRecordFormDS = {
  fields: [{
    name: 'checkType',
    type: 'string',
    lookupCode: 'CIAM.PERMISSION_CHECK.STATE',
    label: intl.get('ciam.missPermission.model.missPermission.checkType').d('检查状态')
  }, {
    name: 'clearType',
    type: 'string',
    lookupCode: 'CIAM.PERMISSION_CHECK.CLEAR_TYPE',
    label: intl.get('ciam.missPermission.model.missPermission.clearType').d('范围'),
    required: true
  }]
};
var detailFormDS = {
  dateKey: 'content',
  fields: [{
    name: 'permissionCode',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.permissionCode').d('权限编码')
  }, {
    name: 'serviceName',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.serviceName').d('服务名称')
  }, {
    name: 'apiPath',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.apiPath').d('API路径')
  }, {
    name: 'checkState',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.checkState').d('检查状态')
  }, {
    name: 'checkStateMeaning',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.checkStateMeaning').d('检查状态描述')
  }, {
    name: 'apiMethodMeaning',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.apiMethodMeaning').d('请求方式')
  }, {
    name: 'permissionType',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.permissionType').d('权限类型')
  }, {
    name: 'creationDate',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.creationDate').d('日期')
  }, {
    name: 'permissionDetails',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.permissionDetails').d('权限详细信息')
  }, {
    name: 'routeDetails',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.routeDetails').d('路由详细信息')
  }, {
    name: 'userDetails',
    type: 'string',
    label: intl.get('ciam.missPermission.model.missPermission.userDetails').d('用户详细信息')
  }],
  transport: {
    read: function read(config) {
      var params = config.params,
          data = config.data;
      var permissionCheckId = data.permissionCheckId;
      var url = VERSION_IS_OP ? "".concat(CPAAS_IAM, "/v1/").concat(organizationId, "/permission-check/").concat(permissionCheckId) : "".concat(CPAAS_IAM, "/v1/permission-check/").concat(permissionCheckId);
      return {
        data: data,
        params: params,
        url: url,
        method: 'GET'
      };
    }
  }
};
export { checkStatusFormConfigDS, searchFormConfigDS, tableConfigDS, permissionSetDS, clearPermissionRecordFormDS, detailFormDS };